class Solution67 {
    public String addBinary(String a, String b) {
        if(a == null || a.length() == 0 ) return b ; 
        if(b == null || b.length() == 0 ) return a ; 
        StringBuilder strbu = new StringBuilder() ;
        char[] arr = a.toCharArray() ;
        char[] brr = b.toCharArray() ;
        int i=arr.length-1 , j = brr.length-1 , ret = 0 ; 
        int sum = 0 ; 
        while(i >= 0 && j >= 0){
            sum =( (arr[i]-'0') + (brr[j]-'0') + ret ) %2 ;  
            ret = ( (arr[i]-'0') + (brr[j]-'0') + ret ) / 2 ;  
            strbu.append(sum) ; 
            i-- ;
            j-- ; 
        }
        while(i >= 0 ){
            sum =( (arr[i]-'0') + ret ) %2 ;  
            ret = ( (arr[i]-'0') + ret ) / 2 ;  
            strbu.append(sum) ; 
            i -- ;
        }
        while(j >= 0){
            sum =((brr[j]-'0') + ret ) % 2 ;  
            ret = ( (brr[j]-'0') + ret ) / 2 ;  
            strbu.append(sum) ; 
            j -- ; 
        }
        if(ret != 0){
            strbu.append(ret) ; 
        }
        return strbu.reverse().toString() ;
    }
}